<style>

</style>


<template>
  <div class="app-container">
    <el-form
      ref="form"
      :rules="rules"
      :model="queryParams"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="关键词" prop="keyWord">
        <el-input
          v-model.trim="queryParams.keyWord"
          placeholder="请输入要爬取的岗位名称"
          clearable
          style="width: 240px"
        />
      </el-form-item>

      <el-form-item label="每页数量" prop="pageSize">
        <el-input
          v-model.number="queryParams.pageSize"
          placeholder="请输入每页数量(小于50)"
          clearable
          style="width: 240px"
        />
      </el-form-item>

      <el-form-item label="页数" prop="pageNum">
        <el-input
          v-model.number="queryParams.pageNum"
          placeholder="请输入爬取页数"
          clearable
          style="width: 240px"
        />
      </el-form-item>

      <el-form-item style="position: center">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="doSpider"
          >实时爬取</el-button
        >
        <el-button
          type="danger"
          icon="el-icon-download"
          size="mini"
          @click="doAynSpider"
        >异步爬取</el-button
        >

        <el-button icon="el-icon-refresh"
                   size="mini"
                   @click="resetQuery"
                  >
          重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-container
      v-loading.container.lock="fullscreenLoading"
      style="height: 350px"
      element-loading-text="正在努力爬取中。。请随便转转或喝口咖啡~~~"

    ></el-container>
  </div>
</template>

<script>
import {
  doSpider,doAynSpider
} from "@/api/sysFunction/functions";





export default {
  name: "JobSpider",
  dicts: [],
  data() {
    return {
      // 遮罩层
      loading: false,
      fullscreenLoading:false,
      // 选中数组
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 是否显示弹出层
      open: false,
      //是否显示弹出层(分配接口)
      openAuthApi: false,
      menuExpand: false,
      menuNodeAll: false,
      resourceExpand: true,
      resourceNodeAll: false,
      // 菜单列表
      menuOptions: [],
      // 资源列表
      resourceOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 10,
        pageSize: 10,
        keyWord: '',
      },

      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        keyWord: [
          { required: true, message: "关键词不能为空", trigger: "blur" },
        ],
        pageSize: [
          { required: true, message: "默认10，最高100", trigger: "blur" },
          { min: 10, max:100, type: "number",  message: '每页数量必须介于 10 和 100 之间', trigger: 'blur'  }
        ],
      },
    };
  },
  created() {
  },
  methods: {


    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（分配接口）
    cancelApiResource() {
      this.openAuthApi = false;
      this.reset();
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      (this.menuExpand = false),
        (this.menuNodeAll = false),
        (this.resourceExpand = true),
        (this.resourceNodeAll = false),
        (this.queryParams={});
      this.resetForm("form");
    },


    /** 爬取按钮操作 */
    doSpider() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 发送表单数据
          this.fullscreenLoading = true;
          doSpider(this.queryParams).then(
            (response) => {
              if (response.data==0){
              this.$modal.alertSuccess(response.msg);
              this.fullscreenLoading = false;
              }else {
                this.$modal.alertError(response.msg);
                this.fullscreenLoading = false;
              }
            },
          );
        }
      });
    },
    /** 异步爬取按钮操作 */
    doAynSpider() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 发送表单数据
          doAynSpider(this.queryParams).then(
            (response) => {
              if (response.data == 0) {
                this.$modal.alertSuccess(response.msg);
              } else {
                this.$modal.alertError(response.msg);
              }
            },
          );
        }
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("form");
      // this.handleQuery();
    },

}};
</script>
